<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

    <meta name="author" content="WD">





<title>深度学习Tensorflow2.2 GPU框架搭建 | WD&#39;s blog</title>



    <link rel="icon" href="/favicon1.ico">




    <!-- stylesheets list from _config.yml -->
    
    <link rel="stylesheet" href="/css/style.css">
    



    <!-- scripts list from _config.yml -->
    
    <script src="/js/script.js"></script>
    
    <script src="/js/tocbot.min.js"></script>
    
    <script src="/js/snow.js"></script>
    



    
    
        
    


<meta name="generator" content="Hexo 5.4.0"></head>
<body>
    <div class="wrapper">
        <header>
    <nav class="navbar">
        <div class="container">
            <div class="navbar-header header-logo"><a href="/">WD&#39;s Blog</a></div>
            <div class="menu navbar-right">
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/tag">Tags</a>
                
                    <a class="menu-item" href="/about">About</a>
                
                <input id="switch_default" type="checkbox" class="switch_default">
                <label for="switch_default" class="toggleBtn"></label>
            </div>
        </div>
    </nav>

    
    <nav class="navbar-mobile" id="nav-mobile">
        <div class="container">
            <div class="navbar-header">
                <div>
                    <a href="/">WD&#39;s Blog</a><a id="mobile-toggle-theme">·&nbsp;Light</a>
                </div>
                <div class="menu-toggle" onclick="mobileBtn()">&#9776; Menu</div>
            </div>
            <div class="menu" id="mobile-menu">
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/tag">Tags</a>
                
                    <a class="menu-item" href="/about">About</a>
                
            </div>
        </div>
    </nav>

</header>
<script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
</script>
        <div class="main">
            <div class="container">
    
    
        <div class="post-toc">
    <div class="tocbot-list">
    </div>
    <div class="tocbot-list-menu">
        <a class="tocbot-toc-expand" onclick="expand_toc()">Expand all</a>
        <a onclick="go_top()">Back to top</a>
        <a onclick="go_bottom()">Go to bottom</a>
    </div>
</div>

<script>
    document.ready(
        function () {
            tocbot.init({
                tocSelector: '.tocbot-list',
                contentSelector: '.post-content',
                headingSelector: 'h1, h2, h3, h4, h5',
                collapseDepth: 1,
                orderedList: false,
                scrollSmooth: true,
            })
        }
    )

    function expand_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 6,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "collapse_toc()");
        b.innerHTML = "Collapse all"
    }

    function collapse_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 1,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "expand_toc()");
        b.innerHTML = "Expand all"
    }

    function go_top() {
        window.scrollTo(0, 0);
    }

    function go_bottom() {
        window.scrollTo(0, document.body.scrollHeight);
    }

</script>
    

    
    <article class="post-wrap">
        <header class="post-header">
            <h1 class="post-title">深度学习Tensorflow2.2 GPU框架搭建</h1>
            
                <div class="post-meta">
                    
                        Author: <a itemprop="author" rel="author" href="/about/">WD</a>
                     &nbsp;

                    
                        <span class="post-time">
                        Date: <a href="#">March 25, 2021&nbsp;&nbsp;11:37:30</a>
                        </span>
                     &nbsp;
                    
                        <span class="post-category">
                    Category:
                            
                                <a href="/categories/Deep-Learning/">Deep Learning</a>
                            
                        </span>
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <br>
    <span id="busuanzi_container_site_pv">总阅读量:<a href="#"><span id="busuanzi_value_page_pv"></span></a>次</span>&nbsp;
    <span class="post-count">文章字数:<a href="#">909</span></a>&nbsp;
     <span class="post-count">阅读时长:<a href="#">3</span>min</a>
                    
                </div>
            
        </header>

        <div class="post-content">
            <h2 id="说在前面"><a href="#说在前面" class="headerlink" title="说在前面"></a>说在前面</h2><ul>
<li>毕设是目标检测、图像识别分类、深度学习、CNN框架等，推荐使用Vs Code(代码编辑器) + miniconda(python包管理工具) + Tensorflow2.2 GPU(深度学习开源框架) 环境。</li>
</ul>
<h2 id="1-miniconda安装"><a href="#1-miniconda安装" class="headerlink" title="1.miniconda安装"></a>1.miniconda安装</h2><ul>
<li><p>miniconda 是 conda 的轻便版本，只有几百MB，功能和conda一样，所以推荐安装miniconda，下载参考<a target="_blank" rel="noopener" href="https://blog.csdn.net/XiangpingZhang/article/details/104324606">https://blog.csdn.net/XiangpingZhang/article/details/104324606</a> 并根据教程更改使用清华镜像源，方便后面下载python包更快。</p>
</li>
<li><p>输入命令<code>conda create --name TF_GPU python=3.7</code>创建属于自己的环境，‘TF_GPU’是环境的名字，自己可以更改，<strong>python 版本推荐使用Python3.7 ！！！（因为要和tensorflow版本对应）</strong></p>
</li>
<li><p>之后输入命令<code>conda activate TF_GPU</code>可以从base 环境进入创建的TF_GPU环境，如下图所示：</p>
<p><img src="https://img-blog.csdnimg.cn/20210325112718821.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="image-20210315121646937"></p>
</li>
</ul>
<h2 id="2-安装Tensorflow-GPU2-2-版本"><a href="#2-安装Tensorflow-GPU2-2-版本" class="headerlink" title="2. 安装Tensorflow GPU2.2 版本"></a>2. 安装Tensorflow GPU2.2 版本</h2><ul>
<li><p>Tensorflow 推荐安装GPU2.2， 可以实现GPU加速，运行更快，<strong>版本不要变，因为要和后面下载的CUDA 和CUDNN进行严格对应，如果不对应就失败！！！</strong></p>
</li>
<li><p>下载的时候一定要进入刚刚创建的环境tf_GPU里下载，以后所有的python包都在这个环境中下载。</p>
</li>
<li><p>执行命令<code>pip install tensorflow-gpu==2.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple</code></p>
<p>-i 是使用的清华源。</p>
</li>
<li><p>安装完之后可以使用命令<code>pip list</code>查看已经安装的包。</p>
</li>
</ul>
<h2 id="3-安装CUDA和CUDNN"><a href="#3-安装CUDA和CUDNN" class="headerlink" title="3. 安装CUDA和CUDNN"></a>3. 安装CUDA和CUDNN</h2><ul>
<li><p>CUDA和CUDNN要和tensorflow 版本对应，具体对应表详见：<a target="_blank" rel="noopener" href="https://blog.csdn.net/sunmingyang1987/article/details/102872658。">https://blog.csdn.net/sunmingyang1987/article/details/102872658。</a></p>
</li>
<li><p>我们就使用Tensorflow2.2 + CUDA10.1 + cudnn7.6.5 （再次提醒，版本号一定不要变！！！）</p>
</li>
<li><p>如果前面安装miniconda的时候已经换过镜像源了，就可以直接运行命令：<code>conda install cudatoolkit=10.1</code> 和<code>conda install cudnn=7.6.5</code>完成安装。</p>
</li>
<li><p>如果前面没有更换清华镜像源，则执行以下命令：<code>conda install cudatoolkit=10.1 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/</code></p>
<p><code>conda install cudnn=7.6.5 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/</code></p>
</li>
</ul>
<h2 id="4-测试"><a href="#4-测试" class="headerlink" title="4.测试"></a>4.测试</h2><ul>
<li><p>至此所有我们需要安装的东西都安装完了，下面为确保成功，进行简单测试：进入tf_GPU环境，输入<code>python</code>进入python提示符&lt;&lt;&lt;</p>
</li>
<li><p>输入<code>import tensorflow as tf</code></p>
</li>
<li><p>然后输入<code>tf.test.is_gpu_available()</code>,如果显示为True，则证明以上全部安装正确，该深度学习环境可以使用。如下图所示：在这里可以看到我们使用的GPU型号等信息，如果显示False则证明安装失败，就查看是那部分没有加载出来（一般都是CUDNN和CUDA没有匹配，所以按照上面版本号安装应该没问题）</p>
<p><img src="https://img-blog.csdnimg.cn/20210325113226884.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="image-20210315123539244"></p>
<p><img src="https://img-blog.csdnimg.cn/20210325113237955.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="image-20210315123618184"></p>
</li>
</ul>
<h2 id="5-与Vs-Code-结合"><a href="#5-与Vs-Code-结合" class="headerlink" title="5.与Vs Code 结合"></a>5.与Vs Code 结合</h2><ul>
<li><p>Vs Code 安装大家可自行百度，网上有很多，包括安装python解释器，如何安装python调试环境等等，这里就说一下如何在Vs Code 中导入我们建立的TF_GPU环境。很简单只需要点击左下角，他会弹出中间的框（如2所示），这里有我们电脑上所有的python环境，只需要找到我们创建的tf_GPU就可以，其次，在下方命令行也可以直接进入tf_GPU环境，非常方便，所以推荐使用Vs Code。</p>
<p><img src="https://img-blog.csdnimg.cn/20210325113315828.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwMTgxNTky,size_16,color_FFFFFF,t_70#pic_center" alt="image-20210315124502530"></p>
</li>
</ul>
<h2 id="结尾"><a href="#结尾" class="headerlink" title="结尾"></a>结尾</h2><ul>
<li><p>最后有关深度学习，CNN等方向的同学，有遇到任何安装问题或者搭建网络问题都可以来问我，欢迎大家提问。</p>
</li>
<li><p>最后推荐几个深度学习的B站视频：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1HV411q7xD?p=113&amp;t=509">https://www.bilibili.com/video/BV1HV411q7xD?p=113&amp;t=509</a> （理论+实战 偏实战）</p>
<p>​    <a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV155411t7ad?p=1">https://www.bilibili.com/video/BV155411t7ad?p=1</a>  （深度学习理论+实战偏理论）</p>
</li>
<li><p>文档参考我群里发的PDF</p>
</li>
</ul>

        </div>

        
            <section class="post-copyright">
                
                    <p class="copyright-item">
                        <span>Author:</span>
                        <span><a href="/about/">WD</a></span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>Permalink:</span>
                        <span><a href="https://did321.gitee.io/2021/03/25/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0Tensorflow2-2-GPU%E6%A1%86%E6%9E%B6%E6%90%AD%E5%BB%BA/">https://did321.gitee.io/2021/03/25/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0Tensorflow2-2-GPU%E6%A1%86%E6%9E%B6%E6%90%AD%E5%BB%BA/</a></span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>License:</span>
                        <span>Copyright (c) 2022 <a target="_blank" rel="noopener" href="http://creativecommons.org/licenses/by-nc/4.0/">CC-BY-NC-4.0</a> LICENSE</span>
                    </p>
                
                
                     <p class="copyright-item">
                         <span>Slogan:</span>
                         <span><a href="#">The blog is my giant.</a></span>
                     </p>
                

            </section>
        
        <section class="post-tags">
            <div>
                <span>Tag(s):</span>
                <span class="tag">
                    
                    
                        <a href="/tags/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/"># 深度学习</a>
                    
                        <a href="/tags/TensorFlow/"># TensorFlow</a>
                    
                        
                </span>
            </div>
            <div>
                <a href="javascript:window.history.back();">back</a>
                <span>· </span>
                <a href="/">home</a>
            </div>
        </section>
        <section class="post-nav">
            
                <a class="prev" rel="prev" href="/2021/03/26/%E5%8D%B7%E7%A7%AF%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9CCNN%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%EF%BC%88%E4%B8%80%E6%96%87%E6%90%9E%E5%AE%9ACNN%EF%BC%89/">卷积神经网络CNN学习笔记（一文搞定CNN）</a>
            
            
            <a class="next" rel="next" href="/2021/03/21/hello-world/">Hello World</a>
            
        </section>
        <br>
        <br>
    
    <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
    <div id="vcomments"></div>
    <script>
        new Valine({
    el: '#vcomments' ,

    appId: 'JvFy3ebVLo2rUYgHaMweJyXX-MdYXbMMI',
    appKey: 'TCFxfjDAM8UmERPEgYXJmT40',
    serverURLs: 'https://JvFy3ebV.api.lncldglobal.com', 
    placeholder: '----评论区----留下你的评论，作者会定期回复！在昵称处填写QQ号可自动获取邮箱和QQ头像（保护QQ邮箱隐私）',
    enableQQ: true,
    requiredFields: ['nick'],
});
    </script>

    </article>
</div>

        </div>
        <footer id="footer" class="footer">
    <div class="copyright">
        <span>© WD | Powered by <a href="https://hexo.io" target="_blank">Hexo</a> & <a href="https://github.com/Siricee/hexo-theme-Chic" target="_blank">Chic</a></span>
    </div>
</footer>

    </div>
</body>

</html>
